import {expect} from 'chai'
import {describe} from 'mocha'
import * as util from '../src/util'
import {masking} from '../src/util'

describe('测试 encryptURL 方法', () => {
    it('仓库地址包含用户名密码', () => {
        let url = 'https://sasasas:asasssa@127.0.0.1/flow-step/CloneRepoList.git'
        let result = util.maskPassword(url)
        expect(result).equal('https://******:******@127.0.0.1/flow-step/CloneRepoList.git')
    })
    it('仓库地址不包含用户名密码', () => {
        let url = 'https://127.0.0.1/flow-step/CloneRepoList.git'
        let result = util.maskPassword(url)
        expect(result).equal('https://127.0.0.1/flow-step/CloneRepoList.git')
    })
    it('仓库地址ssh 地址', () => {
        let url = 'git@atomgit.com:flow-step/CloneRepoList.git'
        let result = util.maskPassword(url)
        expect(result).equal('git@atomgit.com:flow-step/CloneRepoList.git')
    })

})

describe('masking function', () => {

    it('should mask the password in http url', () => {
        const input = Error('git clone http://username:password@example.com --branch master');
        const expectedOutput = 'git clone http://username@example.com --branch master';
        expect(masking(input.message)).to.equal(expectedOutput);
    });

    it('should mask the password in https url', () => {
        const input = 'https://username:password@example.com';
        const expectedOutput = 'https://username@example.com';
        expect(masking(input)).to.equal(expectedOutput);
    });

});
